﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using ESOL.Common.Entity;
using ESOL.Common;
using ESOL.Business.Mst;

namespace ESOL.WinUI.Bpt
{
    public partial class frmMaintainEncoder : BaseForm.frmBaseDialogyBusinessForm
    {
        #region Variable
        public MstProductEntity SelectedProduct { get; set; }
        List<string> Listcondition = new List<string>();
        List<string> ListProductId = new List<string>();
        #endregion

        #region Constructor
        public frmMaintainEncoder()
        {
            InitializeComponent();
            ShowSaveNewButton = true;
        }
        #endregion

        #region Functions
        private void BindComboBox()
        {
            UICommon.UICommonFunctions.BindComboboxByCommonItem(cmbUnit, "UNIT", true);
            UICommon.UICommonFunctions.BindComboboxByCommonItem(cmbMinorUnit, "UNIT", true);
            UICommon.UICommonFunctions.BindComboboxByCommonItem(cmbCodeType, "RCT", true);
            UICommon.UICommonFunctions.BindGridComboboxByCommonItem(repositoryItemGridLookUpEdit1, "RCT", true);
        }

        private void BindDataGrid(string itemType)
        {
            if (string.IsNullOrEmpty(itemType))
            {
                gvMain.DataSource = null;
            }
            DataTable dt = new DataTable();
            //dt = MstCommonItemBs.GetMstCommonItemDtByType(itemType);
            gvMain.DataSource = dt;
        }

        private void SetFields()
        {
            if (SelectedProduct == null)
            {
                return;
            }
            DataTable dt=new DataTable();
            string condition="AND P.PRODUCT_TYPE_ID = '"+SelectedProduct.ProductTypeId+"' ";
            string orderBy=" P.PRODUCT_CODE";
            dt = MstProductBs.GetByCondition(condition, orderBy, "10");
            if (dt.Rows.Count > 0)
            {
                txtBroadClassCode.Text = dt.Rows[0]["PRODUCT_TYPE_CODE2"].ToString();
                txtBroadClassName.Text = dt.Rows[0]["PRODUCT_TYPE_NAME2"].ToString();
                txtMiddleClassCode.Text = dt.Rows[0]["PRODUCT_TYPE_CODE1"].ToString();
                txtMiddleClassName.Text = dt.Rows[0]["PRODUCT_TYPE_NAME1"].ToString();
            }
            else
            {
                txtBroadClassCode.Text = "";
                txtBroadClassName.Text = "";
                txtMiddleClassCode.Text = "";
                txtMiddleClassName.Text = "";
            }
            txtTypeCode.Text = SelectedProduct.TypeCode;
            txtTypeName.Text = SelectedProduct.TypeName;
            txtMaterialCode.Text = SelectedProduct.MaterialCode;
            txtMaterialName.Text = SelectedProduct.Material;
            txtStandardCode.Text = SelectedProduct.StdCode;
            txtStandardName.Text = SelectedProduct.StdName;
            txtProductCode.Text = SelectedProduct.ProductCode;
            txtProductName.Text = SelectedProduct.ProductName;
            txtRemark.Text = SelectedProduct.Description;

            cmbUnit.SetSelectedValue(SelectedProduct.Unit);
            cmbMinorUnit.SetSelectedValue(SelectedProduct.MinorUnit);
            txtSuggestPrice.Text = SelectedProduct.SuggestPrice.ToString();
            if (SelectedProduct.Formual != 0)
            {
                txtFormual.Text = SelectedProduct.Formual.ToString();
            }
            //cmbDeleteFlag.SelectedIndex(SelectedProduct.DeleteFlag);
            cmbCodeType.SelectedValue = SelectedProduct.RootCodeType;
            chkIsFlowCode.Checked = false;
            if (Convert.ToString(SelectedProduct.FlowCode) != null && SelectedProduct.FlowCode>0)
            {
                chkIsFlowCode.Checked = true;
            }
            else
            {
                chkIsFlowCode.Checked = false;
            }
        }

        private void SetEntity()
        {
            if (SelectedProduct == null)
            {
                SelectedProduct = new MstProductEntity();
            }
            if (ThisActionType == ActionType.New)
            {
                SelectedProduct.ProductId = Guid.NewGuid().ToString();
            }

            SelectedProduct.RootCodeType = cmbCodeType.SelectedValue.ToString();

            SelectedProduct.ProductTypeId = MstProductBs.GetProductTypeID(txtBroadClassCode.Text, txtMiddleClassCode.Text);
            SelectedProduct.ProductName = txtProductName.Text.Trim();
            SelectedProduct.ProductCode = txtProductCode.Text.Trim();
            SelectedProduct.Material = txtMaterialName.Text;
            SelectedProduct.MaterialCode = txtMaterialCode.Text;
            SelectedProduct.StdName = txtStandardName.Text;
            SelectedProduct.StdCode = txtStandardCode.Text;
            SelectedProduct.TypeName = txtTypeName.Text;
            SelectedProduct.TypeCode = txtTypeCode.Text;
            SelectedProduct.Description = txtRemark.Text;
            if (chkIsFlowCode.Checked)
            {
                
                if (cmbCodeType.SelectedValue.ToString() == "RCT01")//组装件
                {
                    SelectedProduct.FlowCode = Convert.ToInt32(MstProductBs.GetFlowCode());
                    SelectedProduct.ProductCode = "Z" + MstProductBs.GetFlowCode();
                    
                }
                else//非组装件
                {
                    SelectedProduct.ProductCode = "Y" + MstProductBs.GetFlowCode(); ;
                    SelectedProduct.FlowCode = Convert.ToInt32(MstProductBs.GetFlowCode());
                }
            }
            else
            {
                
                SelectedProduct.ProductCode = txtBroadClassCode.Text + txtMiddleClassCode.Text + txtTypeCode.Text + txtStandardCode.Text + txtMaterialCode.Text;
            }
            SelectedProduct.DeleteFlag = 0;
            SelectedProduct.Unit = CommonFunctions.ToString(cmbUnit.SelectedValue);
            SelectedProduct.MinorUnit = CommonFunctions.ToString(cmbMinorUnit.SelectedValue);
            SelectedProduct.Formual = CommonFunctions.ToDecimal(txtFormual.Text);
            SelectedProduct.SuggestPrice = CommonFunctions.ToDecimal(txtSuggestPrice.Text);
        }

        private void BindGrid()
        {
            DataTable dt = MstProductBs.GetProductByIDList(ListProductId);
            gvMain.DataSource = dt;
        }

        private bool CheckData()
        {
            if (chkIsFlowCode.Checked)
            {
                //if (string.IsNullOrEmpty(cmbUnit.SelectedValue.ToString()))
                //{
                //    MessageBox.Show("类型不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                //    return false;
                //}//*
                if (string.IsNullOrEmpty(txtProductName.Text))
                {
                    MessageBox.Show("物料名称不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }
                if (string.IsNullOrEmpty(txtRemark.Text))
                {
                    MessageBox.Show("备注信息不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }
                if (string.IsNullOrEmpty(cmbUnit.SelectedValue.ToString()))
                {
                    MessageBox.Show("主单位不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }
            }
            else
            {
                if (string.IsNullOrEmpty(txtBroadClassName.Text))
                {
                    MessageBox.Show("大类名称不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }
                if (string.IsNullOrEmpty(txtBroadClassCode.Text))
                {
                    MessageBox.Show("大类编码不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }
                if (string.IsNullOrEmpty(txtMiddleClassName.Text))
                {
                    MessageBox.Show("中类名称不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }
                if (string.IsNullOrEmpty(txtMiddleClassCode.Text))
                {
                    MessageBox.Show("中类编码不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }
                if (string.IsNullOrEmpty(txtTypeName.Text))
                {
                    MessageBox.Show("类型名称不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }
                if (string.IsNullOrEmpty(txtTypeCode.Text))
                {
                    MessageBox.Show("类型编码不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }
                if (string.IsNullOrEmpty(txtStandardName.Text))
                {
                    MessageBox.Show("规格名称不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }
                if (string.IsNullOrEmpty(txtStandardCode.Text))
                {
                    MessageBox.Show("规格编码不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }

                if (string.IsNullOrEmpty(txtMaterialName.Text))
                {
                    MessageBox.Show("材质名称不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }
                if (string.IsNullOrEmpty(txtMaterialCode.Text))
                {
                    MessageBox.Show("材质编码不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }
                if (string.IsNullOrEmpty(txtProductName.Text))
                {
                    MessageBox.Show("物料名称不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }
                if (string.IsNullOrEmpty(txtRemark.Text))
                {
                    MessageBox.Show("备注信息不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }
                if (string.IsNullOrEmpty(cmbUnit.SelectedValue.ToString()))
                {
                    MessageBox.Show("主单位不能为空！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }
            }
            return true;
        }

        private bool Save()
        {
            try
            {
                if (CheckData() == false)
                {
                    return false;
                }
                SetEntity();
                if (ThisActionType == ActionType.New)
                {
                    bool isSuccessful = MstProductBs.InsertMstProduct(SelectedProduct);
                    ListProductId.Add(SelectedProduct.ProductId);
                    if (!isSuccessful)
                    {
                        MessageBox.Show("新增失败！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return false;
                    }
                }
                else if (ThisActionType == ActionType.Modify)
                {
                    bool isSuccessful = MstProductBs.UpdateMstProduct(SelectedProduct);
                    if (!isSuccessful)
                    {
                        MessageBox.Show("修改失败！", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return false;
                    }
                }
                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
        }
        #endregion

        #region Event
        protected override void OnShown(EventArgs e)
        {
            if (ThisActionType == ActionType.Modify || ThisActionType == ActionType.View)
            {
                ListProductId.Add(SelectedProduct.ProductId);
            }
            BindComboBox();
            SetFields();
            BindGrid();
            base.OnShown(e);
        }

        protected override void Click_Save()
        {
            if (Save())
            {
                this.DialogResult = DialogResult.OK;
            }
        }

        protected override void Click_SaveNew()
        {
            if (Save())
            {
                ThisActionType = ActionType.New;
                SelectedProduct = new MstProductEntity();
                SelectedProduct.ProductId = Guid.NewGuid().ToString();
                SetFields();
                BindGrid();
            }
        }

        private void txtBroadClassName_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            Listcondition = new List<string>();
            Listcondition.Add(txtBroadClassName.Text);
            Listcondition.Add(txtBroadClassCode.Text);
            frmMaintainEncoderQuery frm = new frmMaintainEncoderQuery();
            frm.ListIn = Listcondition;
            frm.SType = "BroadClassName";
            if (frm.ShowDialog() == DialogResult.OK && frm.aList != null)
            {
                txtBroadClassName.Text = frm.aList[0];
                txtBroadClassCode.Text = frm.aList[1];
            }
            else
            {
                txtBroadClassName.Text = "";
                txtBroadClassCode.Text = "";
            }
        }

        private void txtBroadClassCode_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            Listcondition = new List<string>();
            Listcondition.Add(txtBroadClassName.Text);
            Listcondition.Add(txtBroadClassCode.Text);
            frmMaintainEncoderQuery frm = new frmMaintainEncoderQuery();
            frm.ListIn = Listcondition;
            frm.SType = "BroadClassCode";
            if (frm.ShowDialog() == DialogResult.OK && frm.aList != null)
            {
                txtBroadClassName.Text = frm.aList[0];
                txtBroadClassCode.Text = frm.aList[1];
            }
            else
            {
                txtBroadClassCode.Text = "";
                txtBroadClassName.Text = "";
            }
        }

        private void txtMiddleClassName_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            Listcondition = new List<string>();
            Listcondition.Add(txtBroadClassName.Text);
            Listcondition.Add(txtBroadClassCode.Text);
            Listcondition.Add(txtMiddleClassName.Text);
            Listcondition.Add(txtMiddleClassCode.Text);
            frmMaintainEncoderQuery frm = new frmMaintainEncoderQuery();
            frm.ListIn = Listcondition;
            frm.SType = "MiddleClassName";
            if (frm.ShowDialog() == DialogResult.OK && frm.aList != null)
            {
                txtMiddleClassName.Text = frm.aList[0];
                txtMiddleClassCode.Text = frm.aList[1];
            }
            else
            {
                txtMiddleClassName.Text = "";
                txtMiddleClassCode.Text = "";
            }
        }

        private void txtMiddleClassCode_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            Listcondition = new List<string>();
            Listcondition.Add(txtBroadClassName.Text);
            Listcondition.Add(txtBroadClassCode.Text);
            Listcondition.Add(txtMiddleClassName.Text);
            Listcondition.Add(txtMiddleClassCode.Text);
            frmMaintainEncoderQuery frm = new frmMaintainEncoderQuery();
            frm.ListIn = Listcondition;
            frm.SType = "MiddleClassCode";
            if (frm.ShowDialog() == DialogResult.OK && frm.aList != null)
            {
                txtMiddleClassName.Text = frm.aList[0];
                txtMiddleClassCode.Text = frm.aList[1];
            }
            else
            {
                txtMiddleClassName.Text = "";
                txtMiddleClassCode.Text = "";
            }
        }

        private void txtTypeName_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            Listcondition = new List<string>();
            Listcondition.Add(txtBroadClassName.Text);
            Listcondition.Add(txtBroadClassCode.Text);
            Listcondition.Add(txtMiddleClassName.Text);
            Listcondition.Add(txtMiddleClassCode.Text);
            Listcondition.Add(txtTypeName.Text);
            Listcondition.Add(txtTypeCode.Text);
            frmMaintainEncoderQuery frm = new frmMaintainEncoderQuery();
            frm.ListIn = Listcondition;
            frm.SType = "TypeName";
            if (frm.ShowDialog() == DialogResult.OK && frm.aList != null)
            {
                txtTypeName.Text = frm.aList[0];
                txtTypeCode.Text = frm.aList[1];
            }
            else
            {
                txtTypeName.Text = "";
                txtTypeCode.Text = "";
            }
        }

        private void txtTypeCode_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            Listcondition = new List<string>();
            Listcondition.Add(txtBroadClassName.Text);
            Listcondition.Add(txtBroadClassCode.Text);
            Listcondition.Add(txtMiddleClassName.Text);
            Listcondition.Add(txtMiddleClassCode.Text);
            Listcondition.Add(txtTypeName.Text);
            Listcondition.Add(txtTypeCode.Text);
            frmMaintainEncoderQuery frm = new frmMaintainEncoderQuery();
            frm.ListIn = Listcondition;
            frm.SType = "TypeCode";
            if (frm.ShowDialog() == DialogResult.OK && frm.aList != null)
            {
                txtTypeName.Text = frm.aList[0];
                txtTypeCode.Text = frm.aList[1];
            }
            else
            {
                txtTypeName.Text = "";
                txtTypeCode.Text = "";
            }
        }

        private void txtStandardName_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            Listcondition = new List<string>();
            Listcondition.Add(txtBroadClassName.Text);
            Listcondition.Add(txtBroadClassCode.Text);
            Listcondition.Add(txtMiddleClassName.Text);
            Listcondition.Add(txtMiddleClassCode.Text);
            Listcondition.Add(txtTypeName.Text);
            Listcondition.Add(txtTypeCode.Text);
            Listcondition.Add(txtStandardName.Text);
            Listcondition.Add(txtStandardCode.Text);
            frmMaintainEncoderQuery frm = new frmMaintainEncoderQuery();
            frm.ListIn = Listcondition;
            frm.SType = "StdName";
            if (frm.ShowDialog() == DialogResult.OK && frm.aList != null)
            {
                txtStandardName.Text = frm.aList[0];
                txtStandardCode.Text = frm.aList[1];
            }
            else
            {
                txtStandardName.Text = "";
                txtStandardCode.Text = "";
            }
        }

        private void txtStandardCode_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            Listcondition = new List<string>();
            Listcondition.Add(txtBroadClassName.Text);
            Listcondition.Add(txtBroadClassCode.Text);
            Listcondition.Add(txtMiddleClassName.Text);
            Listcondition.Add(txtMiddleClassCode.Text);
            Listcondition.Add(txtTypeName.Text);
            Listcondition.Add(txtTypeCode.Text);
            Listcondition.Add(txtStandardName.Text);
            Listcondition.Add(txtStandardCode.Text);
            frmMaintainEncoderQuery frm = new frmMaintainEncoderQuery();
            frm.ListIn = Listcondition;
            frm.SType = "StdCode";
            if (frm.ShowDialog() == DialogResult.OK && frm.aList != null)
            {
                txtStandardName.Text = frm.aList[0];
                txtStandardCode.Text = frm.aList[1];
            }
            else
            {
                txtStandardName.Text = "";
                txtStandardCode.Text = "";
            }
        }

        private void txtMaterialName_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            Listcondition = new List<string>();
            Listcondition.Add(txtBroadClassName.Text);
            Listcondition.Add(txtBroadClassCode.Text);
            Listcondition.Add(txtMiddleClassName.Text);
            Listcondition.Add(txtMiddleClassCode.Text);
            Listcondition.Add(txtTypeName.Text);
            Listcondition.Add(txtTypeCode.Text);
            Listcondition.Add(txtStandardName.Text);
            Listcondition.Add(txtStandardCode.Text);
            Listcondition.Add(txtMaterialName.Text);
            Listcondition.Add(txtMaterialCode.Text);
            frmMaintainEncoderQuery frm = new frmMaintainEncoderQuery();
            frm.ListIn = Listcondition;
            frm.SType = "MaterialName";
            if (frm.ShowDialog() == DialogResult.OK && frm.aList != null)
            {
                txtMaterialName.Text = frm.aList[0];
                txtMaterialCode.Text = frm.aList[1];
            }
            else
            {
                txtMaterialName.Text = "";
                txtMaterialCode.Text = "";
            }
        }

        private void txtMaterialCode_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            Listcondition = new List<string>();
            Listcondition.Add(txtBroadClassName.Text);
            Listcondition.Add(txtBroadClassCode.Text);
            Listcondition.Add(txtMiddleClassName.Text);
            Listcondition.Add(txtMiddleClassCode.Text);
            Listcondition.Add(txtTypeName.Text);
            Listcondition.Add(txtTypeCode.Text);
            Listcondition.Add(txtStandardName.Text);
            Listcondition.Add(txtStandardCode.Text);
            Listcondition.Add(txtMaterialName.Text);
            Listcondition.Add(txtMaterialCode.Text);
            frmMaintainEncoderQuery frm = new frmMaintainEncoderQuery();
            frm.ListIn = Listcondition;
            frm.SType = "MaterialCode";
            if (frm.ShowDialog() == DialogResult.OK && frm.aList != null)
            {
                txtMaterialName.Text = frm.aList[0];
                txtMaterialCode.Text = frm.aList[1];
            }
            else
            {
                txtMaterialName.Text = "";
                txtMaterialCode.Text = "";
            }
        }

        private void txtProductName_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            Listcondition = new List<string>();
            Listcondition.Add(txtBroadClassName.Text);
            Listcondition.Add(txtBroadClassCode.Text);
            Listcondition.Add(txtMiddleClassName.Text);
            Listcondition.Add(txtMiddleClassCode.Text);
            Listcondition.Add(txtTypeName.Text);
            Listcondition.Add(txtTypeCode.Text);
            Listcondition.Add(txtStandardName.Text);
            Listcondition.Add(txtStandardCode.Text);
            Listcondition.Add(txtMaterialName.Text);
            Listcondition.Add(txtMaterialCode.Text);
            Listcondition.Add(txtProductName.Text);
            frmMaintainEncoderQuery frm = new frmMaintainEncoderQuery();
            frm.ListIn = Listcondition;
            frm.SType = "ProductCode";
            if (frm.ShowDialog() == DialogResult.OK && frm.aList != null)
            {
                txtProductName.Text = frm.aList[0];
                txtProductCode.Text = frm.aList[1];
            }
            else
            {
                txtProductName.Text = "";
                txtProductCode.Text = "自动生成";
            }
        }

        private void txtRemark_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            Listcondition = new List<string>();
            Listcondition.Add(txtBroadClassName.Text);
            Listcondition.Add(txtBroadClassCode.Text);
            Listcondition.Add(txtMiddleClassName.Text);
            Listcondition.Add(txtMiddleClassCode.Text);
            Listcondition.Add(txtTypeName.Text);
            Listcondition.Add(txtTypeCode.Text);
            Listcondition.Add(txtStandardName.Text);
            Listcondition.Add(txtStandardCode.Text);
            Listcondition.Add(txtMaterialName.Text);
            Listcondition.Add(txtMaterialCode.Text);
            Listcondition.Add(txtProductName.Text);
            Listcondition.Add(txtRemark.Text);
            frmMaintainEncoderQuery frm = new frmMaintainEncoderQuery();
            frm.ListIn = Listcondition;
            frm.SType = "Remark";
            if (frm.ShowDialog() == DialogResult.OK && frm.aList != null)
            {
                txtProductName.Text = frm.aList[0];
                txtProductCode.Text = frm.aList[1];
            }
            else
            {
                //txtProductName.Text = "";
                txtProductCode.Text = "自动生成";
            }
        }
        #endregion

        private void chkIsFlowCode_Click(object sender, EventArgs e)
        {
            if ((Boolean)chkIsFlowCode.EditValue==false)
            {
                txtBroadClassCode.Enabled = false;
                txtBroadClassName.Enabled = false;
                txtMiddleClassCode.Enabled = false;
                txtMiddleClassName.Enabled = false;
                txtTypeCode.Enabled = false;
                txtTypeName.Enabled = false;
                txtStandardCode.Enabled = false;
                txtStandardName.Enabled = false;
                txtMaterialCode.Enabled = false;
                txtMaterialName.Enabled = false;
                cmbCodeType.Enabled = true;
            }
            else
            {
                txtBroadClassCode.Enabled = true;
                txtBroadClassName.Enabled = true;
                txtMiddleClassCode.Enabled = true;
                txtMiddleClassName.Enabled = true;
                txtTypeCode.Enabled = true;
                txtTypeName.Enabled = true;
                txtStandardCode.Enabled = true;
                txtStandardName.Enabled = true;
                txtMaterialCode.Enabled = true;
                txtMaterialName.Enabled = true;
                cmbCodeType.Enabled = false;
            }
        }
    }
}
